//
//  HSScoreViewModal.swift
//  SchoolDemo
//
//  Created by rimi on 16/10/13.
//  Copyright © 2016年 YQ. All rights reserved.
//

import UIKit

typealias scoreCallBack = (_ error : Error?,_ isRersh:Bool) -> ()

class HSScoreViewModal {
    
    var scoreArr: [HSScoreModal] = []
    
    func requestHomeData(finished:@escaping scoreCallBack) {
        guard let key = userInfo["key"] else {
            return
        }
        //接口
        let url = "ZH-schoolname-S-getExamScore"
        //参数
        let id = 0
        
        let parame = ["key":key,"id":id]
        HSNetWorkTools.shared.downloadData(url: url, parameters: parame) {[weak self] (data, err) in
            //            print(data,err)
            //守护
            guard let data = data as? NSDictionary else {
                HSAlertView.bottomAlertView("网络异常，请检查")
                //网络加载失败通知处理器
                finished(err,false)
                return
            }
            switch data ["result"] as! Int {
            case 0:
                //获取字典数组
                let dictArray = data["data"] as! [NSDictionary]
                //保存模型
                var madelArry = [HSScoreModal]()
                
                for dict in dictArray {
                    let scoreWorkModal = HSScoreModal(dict: dict as! [String : Any])
                    madelArry.append(scoreWorkModal)
                    
                }
                self?.scoreArr = madelArry
                //刷新
                finished(nil,true)
            case 1:
                HSAlertView.bottomAlertView("刷好了")
                finished(nil,false)
            default:
                break
            }
        }
        
        
    }
}
